﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.PlcCommon;

namespace Zocono.WCS.Domain.PlcConnectPoolDomain
{
    public interface IPlcConnectionPool
    {
        /// <summary>
        /// 初始化加载所有PLC连接
        /// </summary>
        /// <param name="programeCode"></param>
        /// <returns></returns>
        bool S7LoadAllPlcConnection(List<PlcConnectionInfo> plcConnectionInfos);
        /// <summary>
        /// 查询所有被断开连接的PLCID
        /// </summary>
        /// <returns></returns>
        List<long> S7GetReLoadPlcConnection();
        /// <summary>
        /// 定时加载已经释放的PLC连接
        /// </summary>
        /// <returns></returns>
        bool S7ReLoadPlcConnection(long id, PlcConnectionInfo plcConnection);
        /// <summary>
        /// 按PlcConnectionID和JobName获取Plc连接，获取成功就锁定
        /// </summary>
        /// <param name="plcConnectionID"></param>
        /// <param name="jobName"></param>
        /// <returns></returns>
        PlcConnectionS7 S7GetReadPlcConnection(long plcConnectionID, string jobName);


        /// <summary>
        /// 按PlcConnectionID获取Plc连接
        /// </summary>
        /// <param name="plcConnectionID"></param>
        /// <param name="jobName"></param>
        /// <returns></returns>
        PlcConnectionS7 S7GetReadSoloPlcConnection(long plcConnectionID, string equipmentCode);

        /// <summary>
        /// 释放被锁定的PLC连接
        /// </summary>
        /// <param name="plcConnectionID"></param>
        /// <param name="jobName"></param>
        /// <returns></returns>
        //bool S7FreeReadPlcConnection(long plcConnectionID, string jobName);
        bool S7LockJobReadPlcConnection(string jobName);
        bool S7FreeJobReadPlcConnection(string jobName);
        bool S7CheckJobLockedConnect(string jobName);
        /// <summary>
        /// 按PlcConnectionID获取Plc连接，不锁定
        /// </summary>
        /// <param name="plcConnectionID"></param>
        /// <returns></returns>
        PlcConnectionS7 S7GetWritePlcConnection(long plcConnectionID);
        Task<bool> S7Heartbeat(PlcReadDbInfo plcReadDbInfo);

        bool S7CheckIdExists(long plcID);
    }
}
